package com.ruoyi.backend.controller;

import com.ruoyi.backend.pojo.RestorationProject;
import com.ruoyi.backend.service.RestorationProjectService;
import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.enums.DataSourceType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "生态修复工程项目管理相关接口")
@RequestMapping("/backend/restorationProject")
@RestController
public class RestorationProjectController {

    @Autowired
    private RestorationProjectService restorationProjectService;

    @DataSource(DataSourceType.MASTER)
    @ApiOperation(value = "搜索生态修复工程项目接口")
    @GetMapping("/search")
    public R<List<RestorationProject>> search(@RequestParam(name = "mine_id", required = false) String mineId,
                                              @RequestParam(name = "restoration_name", required = false) String restorationName)
    {

        List<RestorationProject> restorationProjectList = restorationProjectService.search(mineId, restorationName);
        return R.ok(restorationProjectList, "搜索生态修复工程数据成功");
    }

    @DataSource(DataSourceType.MASTER)
    @ApiOperation(value = "上传生态修复工程项目接口")
    @PostMapping("/upload")
    public R<String> upload(@RequestBody RestorationProject restorationProject)
    {

        restorationProjectService.upload(restorationProject);
        return R.ok("上传生态修复工程数据成功");
    }

    @DataSource(DataSourceType.MASTER)
    @ApiOperation(value = "删除生态修复工程项目接口")
    @DeleteMapping("/delete")
    public R<String> delete(@RequestParam("restorationId") Integer restorationId)
    {

        restorationProjectService.delete(restorationId);
        return R.ok("删除生态修复工程数据成功");
    }

    @DataSource(DataSourceType.MASTER)
    @ApiOperation(value = "更新生态修复工程项目接口")
    @PutMapping("/update")
    public R<String> update(@RequestBody RestorationProject restorationProject)
    {

        restorationProjectService.update(restorationProject);
        return R.ok("更新生态修复工程数据成功");
    }

    @DataSource(DataSourceType.MASTER)
    @ApiOperation(value = "获取所有生态修复工程项目接口")
    @GetMapping("/all")
    public R<List<RestorationProject>> searchAll()
    {

        List<RestorationProject> restorationProjectList = restorationProjectService.searchAll();
        return R.ok(restorationProjectList,"获取生态修复工程数据成功");
    }
}
